//
//  TYCommon.swift
//  Livee
//
//  Created by Q on 2020/11/13.
//  Copyright © 2020 TY. All rights reserved.
//  
import UIKit

@_exported import SwiftyJSON
@_exported import KakaJSON
@_exported import SwiftyUserDefaults
@_exported import JXCategoryView
@_exported import Then
@_exported import PKHUD
@_exported import YYText
@_exported import Kingfisher
//@_exported import DZNEmptyDataSet
//@_exported import TUIRoomEngine
//@_exported import JPSuspensionEntrance


let BASE_URL = "https://api.moonrise-beauty.com"//"https://1207api.62.dianchuiguan.com.cn"
let IMAGE_URL = "https://admin.moonrise-beauty.com"//"https://1207admin.62.dianchuiguan.com.cn"
let DetectionIMAGE_URL = "https://api.moonrise-beauty.com"
/// 偏好选择页面返回路径使用
let DetectionIMAGE_URL1 = "https://moonrise-1301447010.cos.ap-guangzhou.myqcloud.com"

let WXAPPID = "wx2e910e8ae30e14d1"
let UNIVERSAL_LINK = "https://www.d24h.hk/"


//let isDebug = false

/// 屏幕宽度
let SCREEN_WIDTH = UIScreen.main.bounds.width

/// 屏幕高度
let SCREEN_HEIGHT = UIScreen.main.bounds.height

/// 减去安全区域之后的高度
let IPhone_HEIGHT: CGFloat = (SCREEN_HEIGHT == 812.0 || SCREEN_HEIGHT == 896 ? SCREEN_HEIGHT - 34 - 24 : SCREEN_HEIGHT)


/// 导航和状态栏高度
let NAVGATION_ADD_STATUSBAR_HEIGHT: CGFloat = STATUSBAR_HEIGHT + 44

/// 导航和状态栏高度
let NAV_HEIGHT: CGFloat = NAVGATION_ADD_STATUSBAR_HEIGHT

/// tabbar高度
let TABBAR_HEIGHT: CGFloat = UITabBarController().tabBar.frame.size.height + 44
//let TABBAR_HEIGHT: CGFloat = FOOT_HEIGHT + 44

/// 状态栏高度
let STATUSBAR_HEIGHT: CGFloat = QITools.getStatusHeight()
/// 底部安全区域的高度
let FOOT_HEIGHT: CGFloat = QITools.getBottomHeight()

/// 是否是IPHONEX
let ISIPHONEX: Bool = (SCREEN_HEIGHT == 812.0 || SCREEN_HEIGHT == 852.0 || SCREEN_HEIGHT == 896 || SCREEN_HEIGHT == 926 ? true : false)

/// 安全区域高度(整体高度 - 导航栏 - 底部安全区域)
let SAFE_AREA_HEIGHT: CGFloat = SCREEN_HEIGHT - NAV_HEIGHT - FOOT_HEIGHT

/**
 *  竖屏底部安全区域
 */
@available(iOS 11.0, *)
let kSafeAreaHeight = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0.00

/// 判断图片路径中是否包含http
func imageUrlStr(str: String) -> URL {
    var imageStr = str.contains("http") ? str : "\(BASE_URL)\(str)"
    imageStr = imageStr.trimmingCharacters(in: .whitespaces)
    return URL(string: imageStr) ?? URL(string: "")!
}
/// 判断图片路径中是否包含http(路径添加api)
func imageUrlStrApi(str: String) -> String {
    return str.contains("http") ? str : "\(BASE_URL)api\(str)"
}

/// 判断图片路径中是否包含http
func imageStrHttp(str: String) -> String {
    let imageStr = str.contains("http") ? str : "\(BASE_URL)\(str)"
    return imageStr
}

/// 创建图片
func imageName(str: String) -> UIImage {
    return UIImage(named: str) ?? UIImage()
}

/// 字体大小
func SYSFONT(ofSize: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: ofSize)
}
func FONT(ofSize: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: ofSize)
}
/// 粗体字大小
func SYSFONTBOLD(ofSize: CGFloat) -> UIFont {
    return UIFont.boldSystemFont(ofSize: ofSize)
}
func FONTBOLD(ofSize: CGFloat) -> UIFont {
    return UIFont.boldSystemFont(ofSize: ofSize)
}

/// 以iPhone6为比例
func SA_SIZE(_ size: CGFloat) -> CGFloat {
    return size * (SCREEN_WIDTH / 375)
}

/// 以iPhoneX的高度为比例
func SH_SIZE(_ size: CGFloat) -> CGFloat {
    return size * (SCREEN_HEIGHT / 812)
}

func ColorWithStr(_ colorStr: String) -> UIColor {
//    ZJUIUtil.color(withHexString: colorStr)
    UIColor.hexString(toColor: colorStr)
//    UIColor(hexString: colorStr, alpha: 1);
}

func ShowHUD(str: String) {
//    HUD.flash(.label(str), delay: 1.5) { _ in
//        
//    }
    SwiftNotice.showText(str)
}

/// 常用的颜色
let MainColor = ColorWithStr("#FC5164")
let Color333333 = ColorWithStr("#333333")
let Color666666 = ColorWithStr("#666666")
let Color999999 = ColorWithStr("#999999")
let ColorEEEEEE = ColorWithStr("#EEEEEE")




/// rgb获取颜色-不带透明度
public func TYColor(_ red: CGFloat, _ green: CGFloat, _ blue: CGFloat, alhpa: CGFloat = 1.0) -> UIColor {
    return UIColor(red: red / 255.0, green: green / 255.0, blue: blue / 255.0, alpha: alhpa)
}

/// rgb获取颜色-带透明度
public func TYColor(_ r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> UIColor {
    return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: a)
}

/// HexColor 支持0xFF55c9c4格式
public func TYColor(_ argb: UInt32) -> UIColor {
    return UIColor(red: (CGFloat)((argb & 0xFF0000) >> 16) / 255.0, green: (CGFloat)((argb & 0xFF00) >> 8) / 255.0, blue: (CGFloat)(argb & 0xFF) / 255.0, alpha: 1.0)
}

//let RandomColor = UIColor(red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1.0)
public func RandomColor() -> UIColor {
    return UIColor(red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1.0)
}

/// HexStyring 支持"#55c9c4"和"55c9c4"格式
public func TYColor(_ hex: String, _ alpha: CGFloat = 1) -> UIColor {
    // 去除空格等
    var cString: String = hex.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines).uppercased()
    // 去除#
    if cString.hasPrefix("#") {
        cString = (cString as NSString).substring(from: 1)
    }
    // 必须为6位
    if cString.count != 6 {
        return UIColor.gray
    }
    // 红色的色值
    let rString = (cString as NSString).substring(to: 2)
    let gString = ((cString as NSString).substring(from: 2) as NSString).substring(to: 2)
    let bString = ((cString as NSString).substring(from: 4) as NSString).substring(to: 2)
    // 字符串转换
    var r: CUnsignedInt = 0, g: CUnsignedInt = 0, b: CUnsignedInt = 0
    Scanner(string: rString).scanHexInt32(&r)
    Scanner(string: gString).scanHexInt32(&g)
    Scanner(string: bString).scanHexInt32(&b)

    return UIColor(red: CGFloat(r) / 255.0, green: CGFloat(g) / 255.0, blue: CGFloat(b) / 255.0, alpha: alpha)
}

/// KeyWinow
let KeyWinow = UIApplication.shared.keyWindow

/// 延迟加载 - delay
public func Delay(_ delay: Double, closure: @escaping () -> Void) {
    let when = DispatchTime.now() + delay
    DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}


typealias voidBlock = ()->()
typealias intBlock = (_ num: Int)->()
typealias floatBlock = (_ num: CGFloat)->()
typealias doubleBlock = (_ num: Double)->()
typealias boolBlock = (_ isS: Bool)->()
typealias indxBlock = (_ index: IndexPath)->()
typealias stringBlock = (_ str: String)->()
typealias anyObjectBlock = (_ a: AnyObject)->()
typealias stringArrayBlock = (_ arr: [String])->()
typealias arrayBlock = (_ arr: [Any])->()
typealias dictionaryBlock = (_ dic: [String: Any])->()
typealias anyBlock = (_ a: Any)->()
typealias dataBlock = (_ data: Data)->()
typealias jsonBlock = (_ json: JSON)->()


